import { Toast } from 'vant';
import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect:'/movielist'
    },
    {
      path: '/movielist',
      component: () => import('../pages/movielist/MovieList'),
    },
    {
      path:'/moviedetail',
      component: () => import('../pages/moviedetail/MovieDetail'),
      meta:{
        isAuth:true,
      }
    },
    {
      path:'/register',
      component: () => import('../pages/register/Register')
    },
    {
      path:'/login',
      component: () => import('../pages/login/Login')
    },
  ],
});


router.beforeEach((to,from,next)=>{
  if(to.meta.isAuth){
    if(localStorage.user){
      next()
    }else {
      Toast('登录才可以查看哦')
    }
  } else {
    next()
  }
})



export default router;